package org.zachary.prosocialbehaviorservice.interfaces;

import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import org.zachary.prosocialbehaviorservice.application.ActivityService;
import org.zachary.prosocialbehaviorservice.application.command.ActivityDTO;
import org.zachary.prosocialbehaviorservice.application.command.ActivitiesDTO;
import org.zachary.prosocialbehaviorservice.application.command.AddActivityTypeCommand;
import org.zachary.prosocialbehaviorservice.application.command.ModifyActivityTypeCommand;
import org.zachary.prosocialbehaviorservice.infrastructure.utils.Result;

import java.util.List;

@Api(tags = "亲社会行为模块——活动大类")
@RestController
@RequestMapping("/activity")
public class ActivityController {
    private final ActivityService activityService;

    public ActivityController(ActivityService activityService) {
        this.activityService = activityService;
    }


    @PostMapping("/add")
    public Result<String> addActivity(@RequestBody AddActivityTypeCommand command) {
        activityService.addActivity(command);
        return Result.success("活动类型添加成功");
    }
    @GetMapping("/delete")
    public Result<String> deleteActivity(@RequestParam("id") Integer id,@RequestParam("logo") String logo){
        activityService.deleteActivity(id,logo);
        return Result.success("删除成功");
    }

    @PostMapping("/modify")
    public Result<String> modifyActivity(@RequestParam("id")Integer id, @RequestBody ModifyActivityTypeCommand command){
        activityService.modifyActivity(id,command);
        return Result.success("修改成功");
    }
    @GetMapping("/item_list")
    public Result<ActivityDTO> getActivityById(@RequestParam("id") Integer id){
        ActivityDTO dto=activityService.loadActivityWithItems(id);
        return Result.success(dto);
    }
    @GetMapping("/list")
    public Result<List<ActivitiesDTO>> loadAllActivity(){
        List<ActivitiesDTO> list=activityService.loadAllActivities();
        return Result.success(list);
    }

}
